package com.telchina.common.controller;

import com.telchina.common.annotation.Log;
import com.telchina.common.core.controller.BaseController;
import com.telchina.common.core.domain.AjaxResult;
import com.telchina.common.domain.WoTaskConfig;
import com.telchina.common.enums.BusinessType;
import com.telchina.common.service.IWoTaskConfigService;
import com.telchina.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * l流程任务配置Controller
 *
 * @author konghao
 * @date 2023-02-21
 */
@RestController
@RequestMapping("/common/taskConfig")
public class WoTaskConfigController extends BaseController {
    @Autowired
    private IWoTaskConfigService woTaskConfigService;

    /**
     * 分页查询l流程任务配置列表
     */
    // @PreAuthorize("@ss.hasPermi('workorder:deptHandle:list')")
    @GetMapping("/list")
    public AjaxResult list(WoTaskConfig woTaskConfig) {
//        IPage<WoTaskConfig> list = woTaskConfigService.selectList(startPage(), woTaskConfig);
        List<WoTaskConfig> list = woTaskConfigService.selectListAll(woTaskConfig);
        return AjaxResult.success(list);
    }

    /**
     * 查询l流程任务配置列表
     */
    // @PreAuthorize("@ss.hasPermi('workorder:deptHandle:list')")
    @GetMapping("/list/all")
    public AjaxResult listAll(WoTaskConfig woTaskConfig) {
        List<WoTaskConfig> list = woTaskConfigService.selectListAll(woTaskConfig);
        return AjaxResult.success(list);
    }

    /**
     * 导出l流程任务配置列表
     */
    // @PreAuthorize("@ss.hasPermi('workorder:deptHandle:export')")
    @Log(title = "l流程任务配置" , businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WoTaskConfig woTaskConfig) {
        List<WoTaskConfig> list = woTaskConfigService.selectListAll(woTaskConfig);
        ExcelUtil<WoTaskConfig> util = new ExcelUtil<WoTaskConfig>(WoTaskConfig.class);
        return util.exportExcel(list, "deptHandle");
    }

    /**
     * 获取l流程任务配置详细信息
     */
    // @PreAuthorize("@ss.hasPermi('workorder:deptHandle:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(woTaskConfigService.selectById(id));
    }

    /**
     * 新增l流程任务配置
     */
    // @PreAuthorize("@ss.hasPermi('workorder:deptHandle:add')")
    @Log(title = "l流程任务配置" , businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public AjaxResult add(@RequestBody WoTaskConfig woTaskConfig) {
        return toAjax(woTaskConfigService.insert(woTaskConfig));
    }

    /**
     * 修改l流程任务配置
     */
    // @PreAuthorize("@ss.hasPermi('workorder:deptHandle:edit')")
    @Log(title = "l流程任务配置" , businessType = BusinessType.UPDATE)
    @PutMapping(value = "/update")
    public AjaxResult edit(@RequestBody WoTaskConfig woTaskConfig) {
        return toAjax(woTaskConfigService.update(woTaskConfig));
    }

    /**
     * 删除l流程任务配置
     */
    // @PreAuthorize("@ss.hasPermi('workorder:deptHandle:remove')")
    @Log(title = "l流程任务配置" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return woTaskConfigService.deleteByIds(ids);
    }
}
